﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;

[System.Serializable]
public partial class UserInfo : ISerialize
{
    public long userId;
    public int gender;//true: Man, false: woman
    public string name;
    public int maritalStatus;
    public int birthYear;
    public int birthMonth;
    public int birthDay;
    public string status;
    public string xingzuo;
    public string locationProvince;
    public string locationCity;
    public string hometownProvince;
    public string hometownCity;
    public string job;
    public string company;
    public int eduation;
    public string school;
    public float height;
    public float weight;
    public int income;
    public bool realNameVerify;
    public bool jobVerify;
    public bool eduVerify;
    public string aboutMe;
    public string familyBackground;
    public string interest;
    public string loveView;
    public string idealCompanion;
    //public string expectedLife;
    public string icon;
    public string tex1;
    public string tex2;
    public string tex3;
    public string tex4;
    public string tex5;
    public string tex6;
    public UserInfo()
    {

    }

    public override string ToString()
    {
        return $"[gender:{gender},birthYear:{birthYear},location:{locationCity},eduation:{eduation}]";
    }
}

public static  class Gender
{
    public const int man = 1;
    public const int woman = 2;
}
public static class MaritalStatus
{
    public const int unmarried = 0;
    public const int inLove = 1;
    public const int divorce = 2;
}
public static class Education
{
    public const int Edu_HighSchool = 1;
    public const int Edu_JuniorCollege = 2;
    public const int Edu_Bachelor = 3;
    public const int Edu_Master = 4;
    public const int Edu_Doctor = 5;
}
[System.Serializable]
public partial class MiniUserInfo : ISerialize
{
    public long userId;
    public int gender;
    public string name;
    public int birthYear;
    public string locationProvince;
    public string locationCity;
    public string hometownProvince;
    public string hometownCity;
    public string job;
    public int eduation;
    public float height;
    public string icon;

    public MiniUserInfo() { }

    public MiniUserInfo(UserInfo userInfo)
    {
        if (userInfo == null) return;

        this.userId = userInfo.userId;
        this.gender = userInfo.gender;
        this.name = userInfo.name;
        this.birthYear = userInfo.birthYear;
        this.locationProvince = userInfo.locationProvince;
        this.locationCity = userInfo.locationCity;
        this.hometownProvince = userInfo.hometownProvince;
        this.hometownCity = userInfo.hometownCity;
        this.job = userInfo.job;
        this.eduation = userInfo.eduation;
        this.height = userInfo.height;
        this.icon = userInfo.icon;
    }
    public override string ToString()
    {
        return $"[userId:{userId},gender:{gender},birthYear:{birthYear},location:{locationCity},eduation:{eduation}]";
    }
}
[System.Serializable]
public partial class UserMoment : ISerialize
{
    public long userId => miniUserInfo.userId;
    public MiniUserInfo miniUserInfo;
    public Moment moment;
    public List<Comment> comments => moment != null? moment.comments:null;

    public UserMoment() { }

    public UserMoment(UserInfo userInfo, Moment m)
    {
        Init(userInfo, m);
    }

    public void Init(UserInfo userInfo, Moment m)
    {
        miniUserInfo = new MiniUserInfo(userInfo);
        this.moment = m;
    }

    public override string ToString()
    {
        return $"name:{miniUserInfo?.name} moment:{moment}";
    }
}
[System.Serializable]
public partial class UserMomentsInfo : ISerialize
{
    public UserInfo user;
    public UserMoment[] moments;
}

[System.Serializable]
public partial class Comment : ISerialize
{
    public long momentUserId;
    public long momentId;
    public long commentId;
    public long userId => miniUserInfo.userId;
    public MiniUserInfo miniUserInfo;
    public string content;
    public List<long> likes = new List<long>();
    public long time;
    public List<SubComment> subComments;
    public Comment() { }


    public void AddLike(long fromUserId)
    {
        if (this.likes == null)
            likes = new List<long>() { fromUserId };
        else
        {
            if (!likes.Contains(fromUserId))
                likes.Add(fromUserId);
        }
    }
    public void RemoveLike(long fromUserId)
    {
        if (this.likes != null)
            likes.Remove(fromUserId);
    }
    public void AddSubComment(SubComment subComment)
    {
        if (this.subComments == null)
            subComments = new List<SubComment>() { subComment };
        else
        {
            if (!subComments.Contains(subComment))
                subComments.Add(subComment);
        }
    }
    public void RemoveSubComment(SubComment subComment)
    {
        if (this.subComments != null)
            subComments.Remove(subComment);
    }

    public override string ToString()
    {
        return $"[momentUserId:{this.momentUserId} momentId:{momentId} commentId:{this.commentId} commentUserId:{this.userId}]";
    }
}

[System.Serializable]
public partial class SubComment : ISerialize
{
    public long fromUserId;
    public long toUserId;
    public string content;
    public long[] likes;
    public long time;
}

[System.Serializable]
public partial class Tex : ISerialize
{
    public byte[] tex;
    public int texWidth;
    public int texHeight;

    public bool isNull => tex == null || tex.Length <= 0;
    public Tex()
    {

    }
    public Tex(byte[] tex, int texWidth, int texHeight)
    {
        this.tex = tex;
        this.texWidth = texWidth;
        this.texHeight = texHeight;
    }

    public static bool IsNull(Tex tex)
    {
        return tex == null || tex.tex == null || tex.tex.Length <= 0;
    }

    public override string ToString()
    {
        return $"[width:{this.texWidth},height:{this.texHeight},length:{this.tex?.Length}]";
    }

}

[System.Serializable]
public partial class Moment : ISerialize
{
    public long userId;
    public long momentId;
    public long time;
    public string content;
    public string location;
    public string topic;
    public int status;
    public List<long> likes = new List<long>();
    public List<Comment> comments = new List<Comment>();
    public string[] texs;

    public Moment() { }

    public void AddLike(long fromUserId)
    {
        if (this.likes == null)
            likes = new List<long>() { fromUserId };
        else
        {
            if(!likes.Contains(fromUserId))
                likes.Add(fromUserId);
        }
    }
    public void RemoveLike(long fromUserId)
    {
        if (this.likes != null)
            likes.Remove(fromUserId);
    }
    public void AddComment(Comment comment)
    {
        if (this.comments == null)
            comments = new List<Comment>() { comment };
        else
        {
            if (!comments.Contains(comment))
                comments.Add(comment);
        }
    }
    public void RemoveComment(Comment comment)
    {
        if (this.comments != null)
            comments.Remove(comment);
    }
    public override string ToString()
    {
        return $"[userId:{userId},id:{momentId},time:{time},likes:{likes.Count},comments:{comments.Count}]";
    }
}

[System.Serializable]
public partial class Apply : ISerialize
{
    public long sourceUserId;
    public long targetUserId;
    public int result;
    public string msg;
    public string rejectMsg;
    public long applyTime;
    public long viewTime;
    public long resultTime;

    public const int Applying = 3;
    public const int ApplyResult_Suc = 1;
    public const int ApplyResult_Fail = 2;

    public Apply() { }

    public Apply(long sourceUserId, long targetUserId, int result, string msg, string rejectMsg, long applyTime, long viewTime, long resultTime)
    {
        this.sourceUserId = sourceUserId;
        this.targetUserId = targetUserId;
        this.result = result;
        this.msg = msg;
        this.rejectMsg = rejectMsg;
        this.applyTime = applyTime;
        this.viewTime = viewTime;
        this.resultTime = resultTime;
    }
}

[System.Serializable]
public partial class Chat : ISerialize
{
    public long userId1;
    public long userId2;
    public Dialogue[] dialogues;
    public int newMsgCount;

    public bool AreUser(long user1,long user2)
    {
        return this.userId1 == user1 && this.userId2 == user2;//|| this.user1 == user2 && this.user2 == user1;
    }
}

[System.Serializable]
public partial class Dialogue : ISerialize
{
    public long time;
    public string message;
    public Dialogue()
    {
    }

    public Dialogue(string content, long time)
    {
        this.time = time;
        this.message = content;
    }
}
